package com.kexin.common.utils;

import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.core.io.ClassPathResource;

import java.util.Properties;

/**
 * @author chen
 * @date 2021/5/8
 */
public class PropertiesUtils {

    public static Object getCommonYml(String filePath,Object key){
        ClassPathResource resource = new ClassPathResource(filePath);
        Properties properties = null;
        try {
            YamlPropertiesFactoryBean yamlFactory = new YamlPropertiesFactoryBean();
            yamlFactory.setResources(resource);
            properties =  yamlFactory.getObject();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        return properties.get(key);
    }

    public static void main(String[] args) {
        System.out.println(getCommonYml("application.yml","spring.profiles.active"));
    }
}
